package LeetCode.month03.day83;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author 16778
 * @date 2025/10/23 9:45
 * @description
 */
public class No3461 {
    static void main() {
        System.out.println(hasSameDigits("3902"));
    }
    public static boolean hasSameDigits(String s) {
        int n = s.length();
        Queue<Integer> queue = new ArrayDeque<>();
        for (int i = 0; i < s.length(); i++) {
            queue.offer(s.charAt(i)-'0');
        }
        while(queue.size()>2){
            int size = queue.size();
            for (int i = 0; i < size-1; i++) {
                Integer x = queue.poll();
                Integer y = queue.peek();
                queue.offer((x+y)%10);
            }
            queue.poll();
        }
        if (queue.poll()!=queue.peek()) return false;
        return true;
    }
}
